var editor;
KindEditor.ready(function(K) {
	editor = K.create('textarea[name="teamDraft.content"]', {
		resizeType : 1,
		allowPreviewEmoticons : false,
		allowImageUpload : false,
		items : [
			'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
			'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
			'insertunorderedlist', '|', 'emoticons', 'image', 'link']
	});
	});


function selectUser(val){
		var url="getGrouphome.action?status="+val;
		openWindow(url,700,400);
	}

function setValue(value,val){
  var arr = eval(value);
  var names = "";
  var ids = "";
  for(i=0;i<arr.length;i++){
    ids =  ids + "," + arr[i].value;
    names = names + "," + arr[i].name;
  }
  if(names.length>0){
    names = names.substring(1);
    ids =  ids.substring(1);
  }
  document.getElementById(val+"names").value=names;
  document.getElementById(val+"ids").value=ids;
}

function getOldValue(val){
  var ids=document.getElementById(val+"ids").value;
  var names=document.getElementById(val+"names").value;
    var array="";
  if(ids!=''&&ids!='null'){
  var idarray=ids.split(",");
  var namearray=names.split(",");
  for(var i=0;i<idarray.length;i++){
  		if(i==0){
  			array+="{\"value\":"+idarray[i]+",\"name\":\""+namearray[i]+"\"}";
  		}else{
  	      array+=",{\"value\":"+idarray[i]+",\"name\":\""+namearray[i]+"\"}";
  	   } 
  }
  }
  return array;
}
	

function saveTeam(url){
	var title=$("#title").val();
	var sHTML = editor.html();
	var cids=$("#sids").val();
	if($.trim(title)==''&&$.trim(title)=='null'){
		alert("标题不能为空！");
		return;	
	}
	if($.trim(sHTML)==''||$.trim(sHTML)=='null'){
			alert("内容不能为空！");
			return;
	}else if(sHTML.length>1000){
		alert("内容不能大于1000！");
	    return;
	}
	if(url=='saveSubmitNext.action'){
		if($.trim(cids)==''||$.trim(cids)=='null'){
		alert("办理人不能为空！");
		return;	
	}
	}
	var table=$("#filetable").find("input[type=\"checkbox\"]");
		var fileId="";
		for(var i=0;i<table.length;i++){
			fileId+="_"+table[i].value;
		}
		$("#fileArray").val(fileId);
		$("#content").val(sHTML);
			var buttons=$("input[type='button']");
			for(var i=0;i<buttons.length;i++){
				buttons[i].disabled=true;
			}
	$.post(url,$("form").serialize(),function(data){
			if(data=='success'){
				alert("操作成功！");
				window.close();
				window.opener.location.href="draftPoliceTeamList.action";
			}else{
				for(var i=0;i<buttons.length;i++){
				buttons[i].disabled=false;
				}
				alert("操作失败！");
			}
		});	

}

function updateTeam(url){
	var title=$("#title").val();
	var sHTML = editor.html();
	 var cids=$("#sids").val();
	if($.trim(title)==''&&$.trim(title)=='null'){
		alert("标题不能为空！");
		return;	
	}
	if($.trim(sHTML)==''||$.trim(sHTML)=='null'){
			alert("内容不能为空！");
			return;
	}else if(sHTML.length>1000){
		alert("内容不能大于1000！");
	    return;
	}
	if(url=='updateSubmitNext.action'){
		if($.trim(cids)==''||$.trim(cids)=='null'){
		alert("办理人不能为空！");
		return;	
		}
	}
	var table=$("#filetable").find("input[type=\"checkbox\"]");
		var fileId="";
		for(var i=0;i<table.length;i++){
			fileId+="_"+table[i].value;
		}
		$("#fileArray").val(fileId);
		$("#content").val(sHTML);
			var buttons=$("input[type='button']");
			for(var i=0;i<buttons.length;i++){
				buttons[i].disabled=true;
			}
	$.post(url,$("form").serialize(),function(data){
			if(data=='success'){
				alert("操作成功！");
				window.close();
				var currentPage=$("currentPage").val();
				window.opener.page(currentPage);
			}else{
				for(var i=0;i<buttons.length;i++){
				buttons[i].disabled=false;
				}
				alert("操作失败！");
			}
		});	

}

